use super::*;

#[test]
fn test_comp_instruction() {
    let instruction = CInstruction::new("D = D-M").unwrap();
    assert_eq!(instruction.dest, Some("D".into()));
    assert_eq!(instruction.comp, "D-M".to_string());
    assert_eq!(instruction.jump, None);

    let instruction = CInstruction::new("D;JGT").unwrap();
    assert_eq!(instruction.dest, None);
    assert_eq!(instruction.comp, "D".to_string());
    assert_eq!(instruction.jump, Some("JGT".into()));
}

#[test]
fn test_cinstruction() {
    let cins = CInstruction::new("D = D-M").unwrap().to_binary().unwrap();
    println!("{cins:#b}");
    assert_eq!(cins, 0b1111010011010000);
    let cins = CInstruction::new("D;JMP").unwrap().to_binary().unwrap();
    println!("{cins:#b}");
    assert_eq!(cins, 0b1110001100000111);
    let cins = CInstruction::new("0;JNE").unwrap().to_binary().unwrap();
    println!("{cins:#b}");
    assert_eq!(cins, 0b1110101010000101);

    let cins = CInstruction::new("JNE").unwrap().to_binary();
    println!("{cins:#?}");
    assert!(cins.is_err());
}
